package com.google.code.yargon.util;

import com.google.code.yargon.Yargon;
import com.google.code.yargon.level.LevelManager;

/** 
 * General smallish static utility methods
 *  
 * @author Mika Myllynen
 *
 */
public class YargonUtil {
	
	/**
	 * Get current system time in milliseconds
	 * 
	 * @return time 
	 */
	public static long getTime() {
	    return System.nanoTime() / 1000000;
	}
	
	/**
	 * Return the next power of two for the given number
	 * 
	 * @see http://stackoverflow.com/questions/4398711/round-to-the-nearest-power-of-two
	 * 
	 * @param num
	 * @return
	 */
	public static int nextPow(int num) {
		num--;
		num |= num >> 1;
		num |= num >> 2;
		num |= num >> 4;
		num |= num >> 8;
		num |= num >> 16;
		num++;
		
		return num;
	}
	
	/**
	 * Get the current level width in pixels
	 * 
	 * @return
	 */
	public static int getLevelWidthPx() {
		return (LevelManager.getInstance().get(0).getWidth() * Yargon.getInstance().getCurrentTileSet().getSize()); 
	}
	
	/** Get the current level height in pixels
	 * 
	 * @return
	 */
	public static int getLevelHeightPx() {
		return (LevelManager.getInstance().get(0).getHeight() * Yargon.getInstance().getCurrentTileSet().getSize()); 
	}
}
